package com.hqyj.tmall.service.serviceImpl;


import com.hqyj.mapper.ProductImageMapper;
import com.hqyj.mapper.ProductMapper;
import com.hqyj.pojo.Product;
import com.hqyj.pojo.ProductImage;
import com.hqyj.tmall.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {
    @Resource
    private ProductMapper productMapper;

    @Autowired
    private ProductImageMapper productImageMapper;

    @Override
    public List<Product> findAll() {
        List<Product> productList = productMapper.selectProductAndProductImage();
        return productList;
    }

    @Override
    public Map<String,Object> selectById(Integer id) {

        HashMap<String, Object> map = new HashMap<>();
        Product product= productMapper.selectId(id);

        Example example = new Example(ProductImage.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("productId",id);
        List<ProductImage> productImages = this.productImageMapper.selectByExample(example);

        map.put("product",product);
        map.put("productImg",productImages);

        return map;
    }

    @Override
    public List<Product> selectByListId(List<Integer> list) {
        List<Product> productList=productMapper.selectByListId(list);
        return productList;
    }
}
